<template>
  <scroll-view class="report-list" scroll-y enable-flex @scrolltolower="loadMore">
    <reportItem class="list-item" v-for="item in list" :key="item.id" isPreview :reportItem="item" :isIndex="true">
    </reportItem>
    <u-loadmore v-if="list.length" class="list-more" :status="moreLoading" :load-text="loadText" />
    <Empty v-if="loaded && !list.length" :baseImg="emptyImg" text="暂无相关内容" :fontWeight="400" class="empty" />
  </scroll-view>
</template>

<script>
import Empty from "@/components/Empty.vue";
import reportItem from "@/components/reportItem";
import { getActivityList } from "@/api/modules/career";

export default {
  components: {
    Empty,
    reportItem,
  },
  props: {
    consultantId: String || Number,
    personId: String || Number,
  },
  data() {
    return {
      list: [],
      moreLoading: "loadmore",
      loadText: {
        loadmore: "加载更多",
        loading: "加载中",
        nomore: "已经到底啦",
      },
      loaded: false,
      emptyImg: this.$imgBaseSelf + "common/empty_1.png",
      pageParams: {
        pageNo: 0,
        pageSize: 20,
      },
    };
  },
  mounted() {
    this.getData();
  },
  methods: {
    loadMore() {
      if (this.moreLoading == "loading" || this.moreLoading == "nomore") return;

      this.getData(true);
    },
    getData(isMore) {
      const params = {
        pageNo: this.pageParams.pageNo,
        pageSize: this.pageParams.pageSize,
        personId: this.personId || 0,
        belongUserId: this.consultantId,
        moduleType: "OCCUPATION_MODULE_TYPE",
      };
      this.moreLoading = "loading";
      getActivityList(params).then((res) => {
        this.loaded = true;
        this.moreLoading = "loadmore";
        if (res.code == 200) {
          if (isMore) {
            this.list.push(...res.data);
          } else {
            this.list = res.data;
          }

          this.pageParams.pageNo++;
          if (this.pageParams.pageNo >= res.pageparam.pages) {
            this.moreLoading = "nomore";
          }
        } else {
          this.moreLoading = "nomore";
          uni.showToast({
            title: res.status_desc,
            icon: "none",
          });
        }
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.report-list {
  height: 100%;
  background-color: $uni-bg-color;
}
</style>
